﻿namespace QiangPiao
{
    using Microsoft.VisualBasic.ApplicationServices;
    using System;
    using System.Collections.ObjectModel;
    using System.Threading;
    using System.Windows.Forms;

    internal class MyApplication : WindowsFormsApplicationBase
    {
        private bool CanLogin;
        private FrmSplashScreen frmScreen;

        public MyApplication() : base(AuthenticationMode.Windows)
        {
            base.EnableVisualStyles = true;
            base.ShutdownStyle = ShutdownMode.AfterMainFormCloses;
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        protected override void OnCreateMainForm()
        {
            base.MainForm = this.frmScreen.fm;
        }

        protected override void OnCreateSplashScreen()
        {
            this.frmScreen = new FrmSplashScreen();
            base.SplashScreen = this.frmScreen;
        }

        protected override bool OnInitialize(ReadOnlyCollection<string> commandLineArgs)
        {
            if (!(commandLineArgs.Contains("/nosplash") || base.CommandLineArgs.Contains("-nosplash")))
            {
                base.ShowSplashScreen();
            }
            while (!this.frmScreen.IsHandleCreated)
            {
                Thread.Sleep(100);
            }
            this.frmScreen.InitData();
            return true;
        }

        protected override void OnRun()
        {
            if (this.frmScreen.IsConnect)
            {
                base.OnRun();
            }
            else
            {
                Application.Exit();
            }
        }

        protected override void OnShutdown()
        {
            base.OnShutdown();
        }
    }
}

